/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.pos.ejb;

import com.pos.domain.AppSetup;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Dipendra
 */
@Stateless
public class SettingEJB {

    @PersistenceContext
    private EntityManager em;

    public AppSetup findAppSetup() {
        List list = this.em.createQuery("select s from AppSetup s").getResultList();
        if (list != null & list.size() > 0) {
            return (AppSetup) list.get(0);
        }
        return null;
    }

    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public void saveSetting(AppSetup setup) {
        if (setup.getId() == null) {
            this.em.persist(setup);
        } else {
            this.em.merge(setup);
        }

    }
}
